import axiosHelper from './axiosApi.js'

const api = {};
/*const HOST = config.API_HOST;*/
//let API_HOST = store.state.apiHost;
//let HOST = localStorage.getItem("apiHost")?"http://"+localStorage.getItem("apiHost"):"http://"+API_HOST;//可以用于忘记服务器设置卸载重装
//let HOST = "http://"+localStorage.getItem("apiHost");//"http://"+"112.33.14.243";
/*const isDev = process.env.NODE_ENV === 'development';*/

const errorHandler = error => {
    return Promise.reject(error);

};
// const getInstance = () => {
//     if(instance != null) {
//         return instance
//     }
//     let HOST = "http://"+store.state.apiHost;
//     instance = axios.create({
//         baseURL: HOST,
//         /*baseURL: "http://"+HOST,*/
//         timeout: 30000
//     });
// // instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
//
//     instance.interceptors.response.use(
//         response => {
//             let res={};
//             res.status=response.status;
//             res.data=response.data;
//
//             /*const code = response.data ? response.data.code : '';*/
//
//             if (res.status === 401) {
//                 router.replace({ name: 'login' })
//                 store.commit('token', '')
//                 return Promise.reject(response.data);//跳转登陆页面
//             }
//             if (res.status >= 300) {
//                 return Promise.reject(response.data);//返回错误状态数据
//             }
//             return res;
//             /*return response.data.data;*///返回正确状态数据
//         },
//         error => {
//             console.log(error);
//             /*if(error.response && error.response.status == 404){
//                 router.push('/blank.vue')//可做404处理
//             }*/
//             /*return Promise.reject(error)*/
//             return Promise.reject(error.response)
//
//         }
//     );
//
// // 添加请求拦截器，在请求头中加token
//     instance.interceptors.request.use(
//         config => {
//
//             if (localStorage.getItem('longitude')) {
//                 config.headers.gis4_longitude = localStorage.getItem('longitude');
//             }
//             if (localStorage.getItem('latitude')) {
//                 config.headers.gis4_latitude = localStorage.getItem('latitude');
//             }
//             if (localStorage.getItem('gis4_imei')) {
//                 config.headers.gis4_imei = localStorage.getItem('gis4_imei')
//             }
//             if (localStorage.getItem('gis4_phone')) {
//                 config.headers.gis4_phone = localStorage.getItem('gis4_phone');
//             }
//             /*if (localStorage.getItem('gis4_time')) {
//                 config.headers.gis4_time = localStorage.getItem('gis4_time');
//             }*/
//             config.headers.gis4_time = new Date().getTime();
//             if (localStorage.getItem('version')) {
//                 config.headers.version = localStorage.getItem('version');
//             }
//             if (localStorage.getItem('userToken')) {
//                 config.headers.Authorization = localStorage.getItem('userToken');
//             }
//             if (localStorage.getItem('workModeId')!==null){
//                 config.headers.gis4_workmode = localStorage.getItem('workModeId');
//             }
//             if (localStorage.getItem('planNo')!==null){
//                 config.headers.WorkPlanNo = localStorage.getItem('planNo');
//             } else{
//                 config.headers.WorkPlanNo = '';
//             }
//             return config;
//         },
//
//         error => {
//             console.log(error);
//             return Promise.reject(error);
//         }
//     );
//
//     return instance;
//
// };

/*const post = (url, params) => instance.post(url, Object.assign({ Authorization: store.state.userToken }, params)).catch(errorHandler);*/

const post = (url, params) => axiosHelper.getInstance().post(url, params).catch(errorHandler);
const get = (url,config) => axiosHelper.getInstance().get(url,config).catch(errorHandler);
api.post = post;
api.get = get;
/***我的axios的封装请求的方法***/
api.loginSyetem = (name,psw) => post('/app/auth/login',{name,psw});
api.sendMapMarkInfo = (Name,markType,STV_begin,STV_end,Longitude,Latitude,instructions)=>post('app/map/markinfo',
    {Name,markType,STV_begin,STV_end,Longitude,Latitude,instructions});
api.sendInfo = (Time,Longitude,Latitude,Speed,WorkModeId,UserId) =>post('/app/map/location',{Time,Longitude,Latitude,Speed,WorkModeId,UserId});
api.sendFailInfo = (Time,Longitude,Latitude,Speed,Altitude,WorkModeId,UserId)=>post('/app/map/location',
    {Time,LongitudeGcj02:Longitude,LatitudeGcj02:Latitude,Speed,Altitude,WorkModeId,UserId});//LongitudeBd09 LatitudeBd09
api.step = (planId,name,methodName,note) =>post('/app/line/step',{planId,name,methodName,note});
api.workModeSet = (id) =>post('/app/work/workmodeset',{id});
api.getKmScale = (Longitude,Latitude,Move) =>post('/app/map/coordinates',{Longitude,Latitude,Move});
/**************************************get方法********************************/

/*api.getPlanById = (id) => get('/app/line/plan/'+id,{headers:userToken});*/
api.getPlanById = (id) => get('/app/line/plan/'+id,{});
api.getPlans = () => get('/app/line/plans',{});
api.getFloodsWarning = () => get('/app/work/warning/',{});
api.getFloodsMessage = () => get('/app/floods/monitors/',{});
api.getWorkMode = (gis4_imei) =>get('/app/work/workmode',{headers:{gis4_imei:gis4_imei}});
api.getVersion = () =>get('/app/device/versions',{});//获取app历史列表
api.logout = () =>get('/app/auth/logout',{});
api.getContacts = (gis4_imei) =>get('/app/ptt/getContacts',{headers:{gis4_imei:gis4_imei}});
api.getMarkType = () =>get('/app/map/marktype',{});

export default api;